package collection.homework.Collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * addAll()
 * containsAll()
 * ratainAll()
 * removeAll()
 */
public class CollectionDemo4 {
    public static void main(String[] args) {
        Collection a = new ArrayList();
        a.add("java1");
        a.add("java2");
        a.add("java3");
        a.add("java4");
        System.out.println("a的集合为:" + a);//a的集合为:[java1, java2, java3, java4]

        Collection b = new ArrayList();
        b.add("python1");
        b.add("python2");
        b.add("python3");
        b.add("python4");
        System.out.println("b的集合为:" + b);//b的集合为:[python1, python2, python3, python4]

        a.add(b);
        System.out.println("a的集合为" + a);//a的集合为[java1, java2, java3, java4, [python1, python2, python3, python4]]
        System.out.println("b的集合为:" + b);//b的集合为:[python1, python2, python3, python4]

        Collection c = new ArrayList();
        c.add("java1");
        c.add("java2");
        boolean b1 = a.contains(b);
        System.out.println("是否包含：" + b1);//true
        boolean c1 = a.contains(c);
        System.out.println("是否包含：" + c1);//false

        a.retainAll(c);
        System.out.println(a);//[java1, java2]
        System.out.println(c);//[java1, java2]

        a.removeAll(c);
        System.out.println(a);//[]
        System.out.println(c);//[java1, java2]
    }
}
